<template>
    <div class="cart">
        <header>购物车</header>
        <div class="cartWrapper">
            <!-- 购物车为空 -->
            <div class="emptyCart" v-show="cartList.length < 1">
                <img src="../assets/style/empty.png" alt="" />
                <div class="title">购物车空空滴~</div>
                <router-link to="/" class="goHome">去逛逛</router-link>
            </div>
            <!-- 购物车有数据 -->
            <div class="contentWrapper" v-show="cartList.length != 0">
                <div
                    class="contentWrapperList"
                    v-for="item in cartList"
                    :key="item.id"
                >
                    <!-- 渲染购物车商品 -->
                    <div class="shopCartListCon">
                        <div class="left">
                            <!-- 是否选中该商品 -->
                            <van-checkbox
                                v-model="item.checked"
                                :name="item.name"
                            ></van-checkbox>
                        </div>

                        <div class="center">
                            <img :src="item.small_image" alt="" />
                        </div>

                        <div class="right">
                            <!-- 商品介绍 -->
                            <p class="rText">{{ item.name }}</p>

                            <div class="bottomContent">
                                <!-- 价格 -->
                                <p>
                                    ￥{{ (item.price * item.count).toFixed(2) }}
                                </p>
                                <div>
                                    <!-- 步进器  控制数量 -->
                                    <van-stepper
                                        v-model="item.count"
                                        min="0"
                                    />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 提交订单 -->
                <van-submit-bar
                    :price="totalPrice"
                    button-text="提交订单"
                    class="conSub"
                >
                    <van-checkbox > 全选 </van-checkbox>
                </van-submit-bar>
            </div>
        </div>
        <div class="lick">
            <p class="lickp">猜你喜欢</p>
            <TabListView></TabListView>
        </div>
    </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import TabListView from '@/components/TabListView.vue';
export default {
    name: "ShoppingCarView",
    components: { TabListView },
    data(){
        return {
            cartList:[],
            checkAll: false, //全选
            totalNum: 0, // 总数量
            totalPrice: 0, // 总价格
            LiuTabData: [],
            LiuFlashSaleData: {},
        }
    },
    created(){
        this.cartList = this.$store.getters.getShoppingData;
        console.log(this.cartList)
    }
}
</script>

<style lang="scss" scoped>
    .cart {
        width: 100%;
        height: 100%;
        overflow: auto;
        background-color: #f5f5f5;
        position: fixed;
        top: 0;
        left: 0;
        color: #333;
        // font-size: .28rem;

        header {
            width: 100%;
            height: 3.2rem;
            font-size: 22px;
            background-color: #fff;
            text-align: center;
            line-height: 2.6rem;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 9;
        }

        .cartWrapper {
            margin-top: 3.2rem;
            .emptyCart {
                display: flex;
                flex-direction: column;
                align-items: center;

                .title {
                    font-size: 20px;
                    margin: 5px 0;
                }

                .goHome {
                    font-size: 18px;
                    width: 5rem;
                    height: 1rem;
                    background-color: #45c763;
                    padding: 0.5rem;
                    color: #fff;
                    border-radius: 1rem;
                    text-align: center;
                    line-height: 1rem;
                }
            }

            .contentWrapper {
                margin-top: 0.5rem;

                .contentWrapperList {
                    background-color: #fff;

                    .shopCartListCon {
                        display: flex;
                        height: 6rem;
                        border-bottom: 0.01rem solid #e0e0e0;
                        margin-bottom: 0.7rem;
                        padding: 0.5rem 0;
                        justify-content: center;
                        align-items: center;

                        .center {
                            width: 5rem;
                            height: 5rem;

                            img {
                                width: 5rem;
                                height: 5rem;
                            }
                        }

                        .right {
                            font-size: 0.8rem;
                            line-height: 2rem;

                            .rText {
                                width: 240px;
                                text-overflow: ellipsis;
                                overflow: hidden;
                                white-space: nowrap;
                            }

                            .bottomContent {
                                display: flex;
                                align-items: center;
                                justify-content: space-between;
                            }
                        }
                    }
                }

                .conSub {
                    position: fixed;
                    bottom: 50px;
                    left: 0;
                }
            }
        }

        .lick {
            width: 100%;

            .lickp {
                font-size: 1.2rem;
                text-align: center;
                color: red;
                padding: 1rem 0;
            }
        }
    }
</style>